package com.huike.game.Activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.huike.game.R;
import com.huike.game.fragment.Game21_1;
import com.huike.game.fragment.Game21_2;
import com.huike.game.fragment.Game21_3;
import com.huike.game.fragment.Game21_4;
import com.huike.game.fragment.Game21_5;
import com.huike.game.fragment.Game21_6;
import com.huike.game.fragment.Game21_7;

import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

public class GameActivity21 extends AppCompatActivity implements View.OnClickListener {

    private ImageView iv_left_image;
    private TextView tv_left_text;
    private TextView tv_content_title;
    private ImageView iv_rigth_image;
    private TextView tv_right_text;
    private ViewPager vp_game21;
    private RadioButton rb_game21_1;
    private RadioButton rb_game21_2;
    private RadioButton rb_game21_3;
    private RadioButton rb_game21_4;
    private RadioButton rb_game21_5;
    private RadioButton rb_game21_6;
    private RadioButton rb_game21_7;
    private List<Fragment> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game21);
        list = new ArrayList<>();
        list.add(new Game21_1());
        list.add(new Game21_2());
        list.add(new Game21_3());
        list.add(new Game21_4());
        list.add(new Game21_5());
        list.add(new Game21_6());
        list.add(new Game21_7());
        initView();

        rb_game21_1.setChecked(true);
        vp_game21.setCurrentItem(0);

        ViewAdaperHolder holder = new ViewAdaperHolder(getSupportFragmentManager());
        vp_game21.setAdapter(holder);

        vp_game21.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

                switch (position){
                    case 0:
                        rb_game21_1.setChecked(true);
                        break;
                    case 1:
                        rb_game21_2.setChecked(true);
                        break;
                    case 2:
                        rb_game21_3.setChecked(true);
                        break;
                    case 3:
                        rb_game21_4.setChecked(true);
                        break;
                    case 4:
                        rb_game21_5.setChecked(true);
                        break;
                    case 5:
                        rb_game21_6.setChecked(true);
                        break;
                    case 6:
                        rb_game21_7.setChecked(true);
                        break;
                }

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });


        rb_game21_1.setOnClickListener(this);
        rb_game21_2.setOnClickListener(this);
        rb_game21_3.setOnClickListener(this);
        rb_game21_4.setOnClickListener(this);
        rb_game21_5.setOnClickListener(this);
        rb_game21_6.setOnClickListener(this);
        rb_game21_7.setOnClickListener(this);

    }

    private void initView() {
        iv_left_image = (ImageView) findViewById(R.id.iv_left_image);
        tv_left_text = (TextView) findViewById(R.id.tv_left_text);
        tv_content_title = (TextView) findViewById(R.id.tv_content_title);
        iv_rigth_image = (ImageView) findViewById(R.id.iv_rigth_image);
        tv_right_text = (TextView) findViewById(R.id.tv_right_text);

        tv_right_text.setVisibility(View.GONE);
        iv_rigth_image.setVisibility(View.GONE);
        tv_content_title.setText("数据分析");
        tv_left_text.setVisibility(View.GONE);
        iv_left_image.setImageResource(R.drawable.tiao);

        vp_game21 = (ViewPager) findViewById(R.id.vp_game21);
        rb_game21_1 = (RadioButton) findViewById(R.id.rb_game21_1);
        rb_game21_2 = (RadioButton) findViewById(R.id.rb_game21_2);
        rb_game21_3 = (RadioButton) findViewById(R.id.rb_game21_3);
        rb_game21_4 = (RadioButton) findViewById(R.id.rb_game21_4);
        rb_game21_5 = (RadioButton) findViewById(R.id.rb_game21_5);
        rb_game21_6 = (RadioButton) findViewById(R.id.rb_game21_6);
        rb_game21_7 = (RadioButton) findViewById(R.id.rb_game21_7);
    }

    @Override
    public void onClick(View view) {

        switch (view.getId()){
            case R.id.rb_game21_1:
                vp_game21.setCurrentItem(0);
                break;
            case R.id.rb_game21_2:
                vp_game21.setCurrentItem(1);
                break;
            case R.id.rb_game21_3:
                vp_game21.setCurrentItem(2);
                break;
            case R.id.rb_game21_4:
                vp_game21.setCurrentItem(3);
                break;
            case R.id.rb_game21_5:
                vp_game21.setCurrentItem(4);
                break;
            case R.id.rb_game21_6:
                vp_game21.setCurrentItem(5);
                break;
            case R.id.rb_game21_7:
                vp_game21.setCurrentItem(6);
                break;
        }

    }

    class ViewAdaperHolder extends FragmentStatePagerAdapter{

        public ViewAdaperHolder(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return list.get(position);
        }

        @Override
        public int getCount() {
            return list.size();
        }
    }

}
